package com.sdkj.controller;

import com.sdkj.pojo.Checkgroup;
import com.sdkj.service.CheckgroupService;
import com.sdkj.service.CheckitemService;
import com.sdkj.util.MessageConstant;
import com.sdkj.util.PageResult;
import com.sdkj.util.QueryPageBean;
import com.sdkj.util.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/checkgroup")
public class CheckgroupController {
    @Resource
    private CheckgroupService checkgroupService;


    @RequestMapping("/saveGroupInfo")
    public Result saveGroupInfo(Integer[] ids, @RequestBody Checkgroup checkgroup){
       boolean flag=checkgroupService.saveGroupInfo(ids, checkgroup);
    if(flag) {
        return  new Result(flag, MessageConstant.ADD_CHECKGROUP_SUCCESS);
    }else{
        return new Result(flag, MessageConstant.ADD_CHECKITEM_FAIL);
        }

    }
    @RequestMapping("findPageInfo")
    public PageResult findPageInfo(@RequestBody QueryPageBean queryPageBean){
        PageResult pageResult=checkgroupService.findPageInfo(queryPageBean);
        return pageResult;
    }
    @RequestMapping("/deleteInfoById")
    public Result deleteInfoById(Integer id){
        boolean flag =  checkgroupService.deleteInfoById(id);
        if (flag){
            return  new Result(flag,MessageConstant.DELETE_CHECKGROUP_SUCCESS);
        }else{
            return  new Result(flag,MessageConstant.DELETE_CHECKGROUP_FAIL);
        }
    }
    //根据检查组的id获取多个检查项的id
    @RequestMapping("/getCheckitemids")
    public Result getCheckitemids(Integer id){
        List<Integer>list=checkgroupService.getCheckitemids(id);
        return  new Result(true,"",list);
    }

    //更新检查组信息
    @RequestMapping("/updateGroupInfo")
    public Result updateGroupInfo(Integer[] ids,@RequestBody Checkgroup checkgroup){
        boolean flag = checkgroupService.updateGroupInfo(ids,checkgroup);
        if (flag){
            return  new Result(flag,MessageConstant.EDIT_CHECKGROUP_SUCCESS);
        }else{
            return  new Result(flag,MessageConstant.EDIT_CHECKGROUP_FAIL);
        }
    }
    //获取所有的检查组信息
    @RequestMapping("/getAllGroupInfo")
    public Result getAllGroupInfo(){
        List<Checkgroup> list =  checkgroupService.getAllGroupInfo();
        return  new Result(true,"",list);
    }


}
